export * from "./date"

/**
 * 传入'2015年08月21日'格式得到相对应的年月日
 * @param {String} str [日期]
 */
export function getNumberBirthday(str = '') {
  if (str.length < 1)
    return {
      year: 0,
      month: 0,
      day: 0,
    }
  let reg = /([\d]+)年([\d]+)月([\d]+)日/
  let arr = str.match(reg)

  return {
    year: RegExp.$1 * 1,
    month: RegExp.$2 * 1,
    day: RegExp.$3 * 1,
  }
}

export function computedTime(time) {
  //传入之前的时间  时间格式为(YY-MM-DD HH:MM:SS)
  let t = time.split(' ')
  // console.log('t===', t)
  let oldTimeFormat = new Date(t[0])
  let nowDate = new Date()
  if (nowDate.getTime() - oldTimeFormat.getTime() > 0) {
    let times = nowDate.getTime() - oldTimeFormat.getTime()
    let days = parseInt(times / (60 * 60 * 24 * 1000))
    // console.log('days', days)
    return days + 1
  }
}

export function getSystem() {
  if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
    return 'ios'
  } else if (/(Android)/i.test(navigator.userAgent)) {
    return 'android'
  }
}

export function isAndroidDevice() {
  if (/(Android)/i.test(navigator.userAgent)) return true;
  return false;
}

export function isIOSDevice() {
  if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) return true;
  return false;
}


export function getQueryStringValue(key) {
	let data = {}

	let src = window.location.href
	let index = src.indexOf('?')
	if (index === -1) return data[key]
	let dataStr = src.substring(src.indexOf('?') + 1)
	let dataArray = dataStr.split('&')
	for (let i = 0; i < dataArray.length; i++) {
		let param = dataArray[i].split('=')
		data[param[0]] = param[1]
	}
	return data[key]
}
